def maximizeTheProfit(n, offers):
    """
    :type n: int
    :type offers: List[List[int]]
    :rtype: int
    """
    dp = [[0] * len(offers) for _ in range(n)]
    for i in range(0,len(offers)):
        if offers[i][0]==0 and offers[i][1]==0:
            dp[0][i] = offers[i][2]
    dp[offers[0][1]][0] = 1
    for i in range(0,n):
        if i==offers[0][1]:
            continue
        else:
            dp[i][0] = 0
    for i in range(1, len(offers)):
        for j in range(1,n):
            dp[i][j] = max(dp[i-1][j],dp[i-1][j])
    return dp[n-1][len(offers)-1]

if __name__ == "__main__":
    n = 5
    offers = [[0, 0, 1], [0, 2, 2], [1, 3, 2]]
    print(maximizeTheProfit(n,offers))